package com.onLineCar.management.controller;


import com.onLineCar.common.core.domain.Result;
import com.onLineCar.management.domain.TShortMessage;
import com.onLineCar.management.domain.request.MessageRequest;
import com.onLineCar.management.service.ITShortMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 短信模板表 前端控制器
 * </p>
 *
 * @author dsr
 * @since 2023-12-12
 */
@RestController
@RequestMapping("/t-short-message")
public class TShortMessageController {


    @Autowired
    private ITShortMessageService itShortMessageService;


    /**
     * 短信模板
     *
     * @param messageRequest
     * @return
     */
    @PostMapping("/shortMessage")
    public Result shortMessage(@RequestBody MessageRequest messageRequest) {
        // 创建固定大小的线程池，包含10个线程
        ExecutorService executor = Executors.newFixedThreadPool(5);
        // 使用executor执行一个任务
        executor.execute(() -> {
            // 如果messageRequest的tag为空，则抛出运行时异常
            if (null == messageRequest.tag) {
                throw new RuntimeException("标识不能为空");
            }
            // 调用itShortMessageService的selectTShortMessageByTag方法，传入messageRequest作为参数
            itShortMessageService.selectTShortMessageByTag(messageRequest);
        });
        // 关闭executor
        executor.shutdown();
        return Result.success();

    }


}
